﻿@model S4Store.Models.AfterSaleReport.AfterSaleReportServiceAdvisorModel
@{
    ViewBag.Title = "CarBrandDecoratingSaleKPI";
    Layout = null;
}
@{
    var daydata = Model.WMDayDatas.Where(o => o.EmployeeId == (Model.BarModel.SearchSellerId ?? 0));
    var config = Model.WMMonthConfigs.Where(o => o.EmployeeId == (Model.BarModel.SearchSellerId ?? 0)).FirstOrDefault();

    if (daydata.Count() == 0 || config==null)
    {
    <text>未找到相关数据</text>
        return;
    }
    
    
}
@Html.Action("ReportBar", "Common", Model.BarModel)
@if (daydata == null)
{
     
    <p>
        找不到该车间主管</p>
         
}
else
{

    var 车间主管总人数 = Model.WMDayDatas.GroupBy(o => o.EmployeeId).Count();
    if (车间主管总人数 == 0)
    { 
         <text>还没有添加车间主管，无法统计数据</text>
        return;
    }
    
    <div style="height: 100%; overflow: auto">
        <div class="pagetitle">
            @(daydata.FirstOrDefault().Employee.Name)车间主管过程管理数据
        </div>
        <table width="100%" style="border-collapse: collapse;" class="reporttable">
            <tr>
                <th align="center">
                    <div>
                        车间主管姓名</div>
                </th>
                <th align="center" class="tb_header_greenbg">
                    <div>
                        车 间 主 管 职 业 资 质
                    </div>
                </th>
                <th align="center" class="tb_header_greenbg">
                    <div>
                        部 门 机 师 总 数
                    </div>
                </th>
                <th align="center" class="tb_header_greenbg">
                    <div>
                        部 门 设 备 工 具 总 数
                    </div>
                </th>
                <th align="center" class="tb_header_greenbg">
                    <div>
                        本 月 工 单 总 数
                    </div>
                </th>
                <th align="center" class="tb_header_greenbg">
                    <div>
                        本 月 累 计 入 厂 台 次
                    </div>
                </th>
                <th align="center" class="tb_header_greenbg">
                    <div>
                        本 月 已 交 车 总 数
                    </div>
                </th>
                <th align="center" class="tb_header_greenbg">
                    <div>
                        功 能 完 好 设 备 工 具 完 好 数
                    </div>
                </th>
                <th align="center" class="tb_header_greenbg">
                    <div>
                        无 效 工 单 数 量
                    </div>
                </th>
                <th align="center" class="tb_header_greenbg">
                    <div>
                        交 车 后 回 厂 返 修 总 数
                    </div>
                </th>
                <th align="center" class="tb_header_greenbg">
                    <div>
                        设 备 完 好 率
                    </div>
                </th>
                <th align="center" class="tb_header_greenbg">
                    <div>
                        工 单 报 废 率
                    </div>
                </th>
                <th align="center" class="tb_header_greenbg">
                    <div>
                        一 次 修 复 率
                    </div>
                </th>
            </tr>
            <tr>
                <td>@daydata.FirstOrDefault().Employee.Name
                </td>
                <td>@daydata.FirstOrDefault().Employee.WorkYear 年
                </td>
                <td>@config.BMJSZS</td>
                <td>@config.BMGJZS</td>
                <td>@daydata.Sum(o => o.BYGDZS)
                </td>
                <td>@daydata.Sum(o => o.LYLJRCTC)
                </td>
                <td>@daydata.Sum(o => o.BYYJCZS)
                </td>
                <td>@daydata.Where(o => o.AddTime.Day == new DateTime(Model.BarModel.Month.Year, Model.BarModel.Month.Month,1).LastOrNowDay()).Sum(o => o.GNWHSBGJZS)
                </td>
                <td>@daydata.Sum(o => o.WXGDSL)
                </td>
                <td>@daydata.Sum(o => o.JCHHCFXZS)
                </td>
                <td
                    @if (Model.StandardConfig.设备完好率目标 > Model.GetSBWHL(daydata.FirstOrDefault().EmployeeId, Model.BarModel.Month.Year, Model.BarModel.Month.Month))
                    {
                            <text>style="background:#ff1100"</text>
                    }
                >@Model.GetSBWHL(daydata.FirstOrDefault().EmployeeId, Model.BarModel.Month.Year, Model.BarModel.Month.Month)%
                </td>
                <td
                    @if (Model.StandardConfig.工单报废率目标 > Model.GetGDBFL(daydata.FirstOrDefault().EmployeeId, Model.BarModel.Month.Year, Model.BarModel.Month.Month))
                    {
                            <text>style="background:#ff1100"</text>
                    }
                >@Model.GetGDBFL(daydata.FirstOrDefault().EmployeeId, Model.BarModel.Month.Year, Model.BarModel.Month.Month)%
                </td>
                <td
                    @if (Model.StandardConfig.一次修复率目标 > Model.GetYCXHL(daydata.FirstOrDefault().EmployeeId, Model.BarModel.Month.Year, Model.BarModel.Month.Month))
                    {
                            <text>style="background:#ff1100"</text>
                    }
                >@Model.GetYCXHL(daydata.FirstOrDefault().EmployeeId, Model.BarModel.Month.Year, Model.BarModel.Month.Month)%
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    车间平均数
                </td>
                <td>@(Math.Round((decimal)Model.WMMonthConfigs.Sum(o=>o.BMJSZS)/(decimal)车间主管总人数,0,MidpointRounding.AwayFromZero))
                </td>
                <td>@(Math.Round((decimal)Model.WMMonthConfigs.Sum(o => o.BMGJZS) / (decimal)车间主管总人数, 0, MidpointRounding.AwayFromZero))
                </td>
                <td>@(Math.Round((decimal)Model.WMDayDatas.Sum(o => o.BYGDZS) / (decimal)车间主管总人数, 0, MidpointRounding.AwayFromZero))
                </td>
                <td>@(Math.Round((decimal)Model.WMDayDatas.Sum(o => o.LYLJRCTC) / (decimal)车间主管总人数, 0, MidpointRounding.AwayFromZero))
                </td>
                <td>@(Math.Round((decimal)Model.WMDayDatas.Sum(o => o.BYYJCZS) / (decimal)车间主管总人数, 0, MidpointRounding.AwayFromZero))
                </td>
                <td>@(Math.Round((decimal)Model.WMDayDatas.Where(o => o.AddTime.Day == new DateTime(Model.BarModel.Month.Year, Model.BarModel.Month.Month, 1).LastOrNowDay()).Sum(o => o.GNWHSBGJZS) / (decimal)车间主管总人数, 0, MidpointRounding.AwayFromZero))
                </td>
                <td>@(Math.Round((decimal)Model.WMDayDatas.Sum(o => o.WXGDSL) / (decimal)车间主管总人数, 0, MidpointRounding.AwayFromZero))
                </td>
                <td>@(Math.Round((decimal)Model.WMDayDatas.Sum(o => o.JCHHCFXZS) / (decimal)车间主管总人数, 0, MidpointRounding.AwayFromZero))
                </td>
                <td>@(Model.GetAvgSBWHL(Model.BarModel.Month.Year, Model.BarModel.Month.Month))%
                </td>
                <td>@(Model.GetAvgGDBFL(Model.BarModel.Month.Year, Model.BarModel.Month.Month))%
                </td>
                <td>@Model.GetAvgYCXHL(Model.BarModel.Month.Year, Model.BarModel.Month.Month)%
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    考核目标
                </td>
                <td>
                </td>
                <td>
                </td>
                <td>
                </td>
                <td>
                </td>
                <td>
                </td>
                <td>
                </td>
                <td>
                </td>
                <td>
                </td>
                <td>@(Model.StandardConfig.设备完好率目标.toInt())%
                </td>
                <td>@(Model.StandardConfig.工单报废率目标.toInt())%
                </td>
                <td>@(Model.StandardConfig.一次修复率目标.toInt())%
                </td>
            </tr>
        </table>
    </div>
}